// https://leetcode.cn/problems/find-common-characters/
// Created by ade on 2022/10/21.
//
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>

using namespace std;

class Solution {
public:
    vector <string> commonChars(vector <string> &words) {
        vector<int> m(26, 0);
        for (auto &c:words[0]) {
            m[c - 'a'] += 1;
        }
        for (int i = 1; i < words.size(); i++) {
            vector<int> tmp(26, 0);
            for (auto &c:words[i]) {
                tmp[c - 'a'] += 1;
            }
            for (int j = 0; j < 26; j++) {
                m[j] = min(m[j], tmp[j]);
            }
        }
        vector <string> res = {};
        for (int i = 0; i < 26; i++) {
            if (m[i] > 0) {
                for (int j = 0; j < m[i]; j++) {
                    res.push_back(string(1, i + 'a'));
                }
            }
        }
        return res;
    }
};

int main() {
    cout << (35 & 2) << endl;
    Solution so;
    vector <string> words = {"bella", "label", "roller"};
    auto a = so.commonChars(words);
    for (auto &i : a) {
        cout << i << endl;
    }
    return 0;
}